//
//  SYHTTableViewCell.m
//  BSHOUYIFANG
//
//  Created by 曹雁彬 on 15/8/13.
//  Copyright (c) 2015年 CYB. All rights reserved.
//

#import "SYHTTableViewCell.h"
#import "Header.h"
#import <UIImageView+WebCache.h>
#import "SYlabelAddImageView.h"
@implementation SYHTTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;

        _titleLable = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 150, 25)];
        _titleLable.font = [UIFont systemFontOfSize:20];
        //_titleLable.text = @"热门圈子";
        [self.contentView addSubview:_titleLable];
        
        _titleView = [[UIView alloc]initWithFrame:CGRectMake(0, 5, 4, 35)];
        _titleView.backgroundColor = [UIColor orangeColor];
        [self.contentView addSubview:_titleView];
        
        _buttonMore = [UIButton buttonWithType:UIButtonTypeCustom];
        _buttonMore.frame = CGRectMake(SCREEN_WIDTH-70, 10, 60, 25);
        //_buttonMore.backgroundColor = [UIColor redColor];
        [_buttonMore setTitle:@"更多 ﹥" forState:UIControlStateNormal];
        [_buttonMore setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [_buttonMore addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:_buttonMore];
        
           SYHTTableViewCell *cell =self;
        
        _labelAddView1 = [[SYlabelAddImageView alloc]initWithFrame:CGRectMake(0, 40, SCREEN_WIDTH, (SCREEN_HEIGHT/6*4-45)/3)];
        //_labelAddView1.backgroundColor = [UIColor greenColor];
        _labelAddView1.webBlock = ^(NSInteger index){
            [cell webBlock:index-1];
        };
        [self.contentView addSubview:_labelAddView1];
        
        _labelAddView2 = [[SYlabelAddImageView alloc]initWithFrame:CGRectMake(0, 40+(SCREEN_HEIGHT/6*4-45)/3, SCREEN_WIDTH, (SCREEN_HEIGHT/6*4-45)/3)];
        //_labelAddView2.backgroundColor = [UIColor greenColor];
        _labelAddView2.webBlock = ^(NSInteger index){
            [cell webBlock:index+2];
        };
        [self.contentView addSubview:_labelAddView2];
        
        _labelAddView3 = [[SYlabelAddImageView alloc]initWithFrame:CGRectMake(0, 40+((SCREEN_HEIGHT/6*4-45)/3)*2, SCREEN_WIDTH, (SCREEN_HEIGHT/6*4-45)/3)];
        //_labelAddView3.backgroundColor = [UIColor greenColor];
        _labelAddView3.webBlock = ^(NSInteger index){
            [cell webBlock:index+5];
        };
        [self.contentView addSubview:_labelAddView3];

    }return self;
}
//block回调 C的方法
- (void)webBlock:(NSInteger)index
{
    if (_homeWebBlock != nil) {
        _homeWebBlock(_model.data[index][@"id"],_model.data[index][@"img"],_model.data[index][@"text"]);
    }
}
- (void)buttonAction:(UIButton *)button
{
    if (_shomeBlock != nil) {
        _shomeBlock(_model.title);
    }
}
-(void)setModel:(SYHomeModel *)model
{
    _model = model;
    [_labelAddView1.bmgView1 sd_setImageWithURL:[NSURL URLWithString:_model.data[0][@"img"]]];
    [_labelAddView1.bmgView2 sd_setImageWithURL:[NSURL URLWithString:_model.data[1][@"img"]]];
     [_labelAddView1.bmgView3 sd_setImageWithURL:[NSURL URLWithString:_model.data[2][@"img"]]];
    _labelAddView1.describe1.text = _model.data[0][@"name"];
    _labelAddView1.describe2.text = _model.data[1][@"name"];
    _labelAddView1.describe3.text = _model.data[2][@"name"];
    [_labelAddView2.bmgView1 sd_setImageWithURL:[NSURL URLWithString:_model.data[3][@"img"]]];
    [_labelAddView2.bmgView2 sd_setImageWithURL:[NSURL URLWithString:_model.data[4][@"img"]]];
     [_labelAddView2.bmgView3 sd_setImageWithURL:[NSURL URLWithString:_model.data[5][@"img"]]];
    _labelAddView2.describe1.text = _model.data[3][@"name"];
    _labelAddView2.describe2.text = _model.data[4][@"name"];
    _labelAddView2.describe3.text = _model.data[5][@"name"];
    [_labelAddView3.bmgView1 sd_setImageWithURL:[NSURL URLWithString:_model.data[6][@"img"]]];
    [_labelAddView3.bmgView2 sd_setImageWithURL:[NSURL URLWithString:_model.data[7][@"img"]]];
     [_labelAddView3.bmgView3 sd_setImageWithURL:[NSURL URLWithString:_model.data[8][@"img"]]];
    _labelAddView3.describe1.text = _model.data[6][@"name"];
    _labelAddView3.describe2.text = _model.data[7][@"name"];
    _labelAddView3.describe3.text = _model.data[8][@"name"];
    
    _titleLable.text = _model.title;

    
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end













